package com.rois.librois.libRoISMessageStorage;

import java.util.Vector;

/**
 * Data folder class for parameter.
 * This object holds a list of:
 * - parameter name
 * - parameter data type
 * - parameter value
 *
 * @author Miki Sato <miki.sato.1225@gmail.com>
 *
 *    The MIT licence
 *
 *    Copyright (C) 2011
 *      ATR Intelligent Robotics and Communication Laboratories, Japan
 *
 *    Permission is hereby granted, free of charge, to any person obtaining a copy
 *    of this software and associated documentation files (the "Software"), to deal
 *    in the Software without restriction, including without limitation the rights
 *    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
 *    of the Software, and to permit persons to whom the Software is furnished to do so,
 *    subject to the following conditions:
 *
 *    The above copyright notice and this permission notice shall be included in all
 *    copies or substantial portions of the Software.
 *
 *    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
 *    INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
 *    PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 *    HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 *    OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 *    SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

public class RoIS_Parameters {
	private static final int DEFAULT_PARAM_MAXSIZE = 100;
	public int size;
	public int max_size;
	public Vector<String> name = new Vector<String>();
	public Vector<String> datatype = new Vector<String>();
	public Vector<String> value = new Vector<String>();

	/**
	 * create data holder.
	 */
	public RoIS_Parameters()
	{
		max_size = DEFAULT_PARAM_MAXSIZE;
		clear();
	}

	/**
	 * clear all data.
	 */
	public void clear()
	{
		size = 0;
		name.clear();
		datatype.clear();
		value.clear();
	}

	/**
	 * get number of parameters.
	 * @return number of parameters
	 */
	public int length()
	{
		return size;
	}

	/**
	 * set number of parameters.
	 * @param n size of the list
	 * @return size
	 */
	public int length(int n)
	{
		for(int i=0; i<n; i++)
		{
			push_back(
				"",
				"",
				""
			);
		}
		return size;
	}

	/**
	 * add parameter at the end of list.
	 * @param _name parameter name
	 * @param _datatype data type of the parameter
	 * @param _value value of the parameter
	 */
	public void push_back(
		String _name,
		String _datatype,
		String _value
	)
	{
		name.add(_name);
		datatype.add(_datatype);
		value.add(_value);
		size++;

		if(size>max_size)
		{
			erase(0);
		}
	}

	/**
	 * remove parameter at the end of list.
	 */
	public void pop_back()
	{
		if(size>0)
		{
			name.remove(name.size()-1);
			datatype.remove(datatype.size()-1);
			value.remove(value.size()-1);
			size--;
		}
	}

	/**
	 * remove specified parameter from list.
	 * @param index index of the parameter
	 */
	public void erase(
		int index
	)
	{
		if(size>0)
		{
			name.remove(index);
			datatype.remove(index);
			value.remove(index);
			size--;
		}
	}
}
